    let phone//手机号
    let couponId//id
    function couponList(){
        // 手机号base64加密
        if(phone){
            let phoneNumEnc = window.btoa(phone);
            $.ajax({
                type: 'GET',
                url: httpUrl + '/api/v1/open/searchCoupon?phoneNumEnc=' + phoneNumEnc,
                success: function(result) {
                    if (result.code =='10000') {
                        const couponList = result.data;
                        // const couponList = result.data.slice(0, 10);
                        couponList.forEach((coupon,index) => {
                            let couponText = coupon.count === 1 ? `首月领取${coupon.denomination}元话费` : `每月领取${coupon.denomination}元话费`; // 判断是否为第一个优惠券
                            let couponImage = '';
                            let clickHandler = '';
                            switch (coupon.receiveStates) {
                                case 0:
                                    couponImage = 'libtnyes.png';
                                    clickHandler = `onclick="toGetTwenty('${coupon.id}')"`;
                                    break;
                                case 1:
                                    couponImage = 'libtnNotyet.png';
                                    break;
                                case 2:
                                    couponImage = 'libtnno.png';
                                    break;
                                case 3:
                                    couponImage = 'libtnpass.png';
                                    break;
                                default:
                                    couponImage = 'libtnyes.png';
                                    break;
                            }
                            let couponItem = `
                        <ul style="width: 100%;margin: 0 auto;position: relative;z-index: 6">
                            <li style=" height: 90px;
                                        width: 100%;
                                        margin-bottom: 15px;
                                        background-image: url('./images/coupon/libgc.png')!important;
                                        background-size: 100% 100%;
                                        background-repeat: no-repeat;
                                        display: flex;
                                        align-items: center;
                                        justify-content: space-between;">
                                <div class="zhan" style=" flex:7;
                                                            display: flex;
                                                            align-items: center;
                                                            flex-direction: column;
                                                           ">
                                     <div class="li_top" style="display: flex;
                                                                align-items: center;
                                                                justify-content: center;">
<!--                                               <img src="./images/coupon/liRmb.png" style="width: 90px"/>-->
                                               <div class="li_top_money" style="width: 75px;color: #fff8e3;display: flex;">
                                                    <div>￥</div>
                                                    <div class="moneyLi" style="font-size: 40px">${coupon.denomination}</div>
                                               </div>
                                                <div class="li_text" style=" display: flex;
                                                                             flex-direction: column;
                                                                              align-items: center;
                                                                                justify-content: center;">
                                                        <span style="font-size: 10px;
                                                                        color: white;
                                                                        display: inline-block;
                                                                        margin-bottom: 5px;">
                                                                        请查看到账短信通知
                                                        </span>
                                                        <span class="ling" style="  font-size: 10px;
                                                                                    color: #a8471d;
                                                                                    padding:5px;
                                                                                    box-sizing: border-box;
                                                                                    border-radius: 20px;
                                                                                    background: linear-gradient(to bottom,
                                                                                    #eec274,
                                                                                    #f1bf88,
                                                                                    #feeac9,
                                                                                    #feeac7,
                                                                                    #ffdfac,
                                                                                    #fedea8,
                                                                                    #f8cd8b,
                                                                                    #eec274);
                                                                                    "
                                                                                    >
                                                          ${couponText}
                                                        </span>
                                                </div>
                                </div>
                                <div class="li_bot" style="font-size: 7px;
                                                            color: white;">
                                有效期：${coupon.startTime} - ${coupon.endTime}
                                </div>

                           </div>
                                <div class="btn" style="flex:3;
                                                        display: flex;
                                                        flex-direction: column;
                                                        align-items: center;
                                                        justify-content: center;">
                                    <img src="./images/coupon/${couponImage}" ${clickHandler} style="width: 60px"/>
                                </div>
                            </li>
                        </ul>
                    `;
                            $('.list_white').append(couponItem);
                        });
                    } else {
                        setTimeout(() => {
                            alert(result.msg);
                        }, 50);
                    }
                },
                error: function(xhr, status, error) {
                    setTimeout(() => {
                        alert('查询失败，请稍后再试。');
                    }, 50);
                }
            });

        }
    }
    function closeWindow(){
        var window1 = document.getElementById('modelSucceed');
        window1.style.display = 'none';
    }
    function getPhone(){
        var p = getQueryVariable('p');
        if (p) {
            phone=p
        }
    }
    function toGetTwenty(id){
        couponId=id
        if(phone){
            var codeDiv = document.querySelector('.model3');
            codeDiv.style.display = 'block';
            // 手机号base64加密
            let phoneNumEnc = window.btoa(phone);
            var postData = {
                phoneNumEnc: phoneNumEnc,
                couponId:couponId
            };
            $.ajax({
                type: 'POST',
                url: httpUrl+'/api/v1/open/receive',
                contentType: 'application/json',
                data: JSON.stringify(postData),
                success: function(result) {
                    codeDiv.style.display = 'none';
                    if(result.code=='10000'){
                        setTimeout(function() {
                            $('.list_white ul').remove();
                            couponList()
                            var window1 = document.getElementById('modelSucceed');
                            window1.style.display = 'block';
                            var text = document.getElementById('textBack');
                            text.textContent = result.msg;
                        }, 1000);
                    }else{
                        setTimeout(()=>{
                            alert(result.msg)
                        },50)
                    }

                },
                error: function(xhr, status, error) {
                    codeDiv.style.display = 'none';
                    setTimeout(()=>{
                        alert('领取失败，请稍后再试。');
                    },50)

                }
            });
        }else{
            alert('网络波动,请返回上一页重试!')
            setTimeout(()=>{
                var targetUrl = 'lq.html';
                var g = getQueryVariable('g');
                if (g) {
                    targetUrl += '?g=' + encodeURIComponent(g);
                }
                window.location.href = targetUrl;
            },50)
        }

    }
    getPhone()
    setTimeout(()=>{
        couponList()
    },50)




